Closed Bug 1759844 Opened 3 years ago Closed 3 years ago

WebGLContextDraw.cpp: the 'empty' method should be used to check for emptiness instead of 'size'

Categories

(Developer Infrastructure :: Source Code Analysis, task, P5)

Tracking

(firefox101 fixed)

RESOLVED FIXED
101 Branch
Tracking Status
firefox101 --- fixed

People

(Reporter: Sylvestre, Assigned: rzvncj, Mentored)

References

(Blocks 1 open bug)

Details

(Keywords: good-first-bug, Whiteboard: [lang=C++])

Attachments

(1 file, 1 obsolete file)

Filling as a good first bug to learn workflows.

intersection.size()
should use .empty() instead

https://searchfox.org/mozilla-central/rev/fa69d8b248e6c1df670aa6b019e30ec37e6672be/dom/canvas/WebGLContextDraw.cpp#333

As the change is trivial, it is just to learn how to contribute to Firefox.

Found by http://clang.llvm.org/extra/clang-tidy/checks/readability-container-size-empty.html

Tutorials to contribute:
https://firefox-source-docs.mozilla.org/tools/docs/contribute/how_to_contribute_firefox.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html

Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.

Severity: -- → N/A
Priority: -- → P5

Use !intersection.empty() instead of bool(intersection.size()) to
check if the container is empty.

Assignee: nobody → rzvncj
Status: NEW → ASSIGNED

Not sure how these changes happened:

@@ -1061,7 +1061,8 @@ bool WebGLContext::DoFakeVertexAttrib0(c
   ////
 
   const auto bytesPerVert = sizeof(mFakeVertexAttrib0Data);
-  const auto checked_dataSize = CheckedInt<intptr_t>(totalVertCount) * bytesPerVert;
+  const auto checked_dataSize =
+      CheckedInt<intptr_t>(totalVertCount) * bytesPerVert;
   if (!checked_dataSize.isValid()) {
     ErrorOutOfMemory(
         "Integer overflow trying to construct a fake vertex attrib 0"
@@ -1081,7 +1082,8 @@ bool WebGLContext::DoFakeVertexAttrib0(c
 
     const auto err = errorScope.GetError();
     if (err) {
-      ErrorOutOfMemory("Failed to allocate fake vertex attrib 0 data: %zi bytes", dataSize);
+      ErrorOutOfMemory(
+          "Failed to allocate fake vertex attrib 0 data: %zi bytes", dataSize);
       return false;
     }

hg diff -c tip (after the commit) shows them, but hg diff (immediately after the change, but some time prior to the commit) did not. Maybe running ./mach lint did it?

Anyway, I can try to figure this out and redo the patch if you'd like (so that the only thing changed is the relevant line). Let me know.

Use !intersection.empty() instead of bool(intersection.size()) to
check if the container is empty.

Figured the automatic indentation out, it was done by hg commit, via clang-format. Updated my .hgrc and now there are no more surprises. Sorry for the inconvenience - I'm really a git user.

Hope all's well with my latest submission. Thanks for the quick review!

Attachment #9271558 - Attachment is obsolete: true
Pushed by sledru@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/eecb5e5f0e0f WebGLContextDraw.cpp: use .empty() instead of .size(). r=andi
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 101 Branch
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: